﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace AdminManagement.Menu
{
    [Authorize]
    [ApiExplorerSettings(GroupName = "v1")]
    public class SysMenuService : ApplicationService
    {
        private readonly IRepository<SysMenu> repository;

        public SysMenuService(IRepository<SysMenu> repository)
        {
            this.repository = repository;
        }

        /// <summary>
        /// 获取路由
        /// </summary>
        /// <returns></returns>
        [HttpGet("/api/v1/menus/routes")]
        public async Task<ResultDto<List<SysMenuDto>>> Routes()
        {
            return new ResultDto<List<SysMenuDto>>
            {
                Code = Code.Success,
                Data = new List<SysMenuDto> {
                    new SysMenuDto
                    {
                        Component = "Layout",
                        Name = "/system",
                        Path = "/system",
                        Redirect = "/system/user",
                        Meta = new Meta
                        {
                            AlwaysShow = false,
                            Hidden = false,
                            Icon = "system",
                            Title = "系统管理"
                        },
                        Children = new List<SysMenuDto> {
                            new SysMenuDto
                            {
                                Component = "system/user/index",
                                Name = "User",
                                Path = "user",
                                Meta = new Meta
                                {
                                    AlwaysShow = false,
                                    Hidden = false,
                                    KeepAlive = true,
                                    Icon = "el-icon-User",
                                    Title = "用户管理"
                                }
                            },
                            new SysMenuDto
                            {
                                Component = "system/menu/index",
                                Name = "SysMenu",
                                Path = "menu",
                                Meta = new Meta
                                {
                                    AlwaysShow = false,
                                    Hidden = false,
                                    KeepAlive = true,
                                    Icon = "menu",
                                    Title = "菜单管理"
                                }
                            },
                            new SysMenuDto
                            {
                                Component = "system/dict/index",
                                Name = "Dict",
                                Path = "dict",
                                Meta = new Meta
                                {
                                    AlwaysShow = false,
                                    Hidden = false,
                                    KeepAlive = true,
                                    Icon = "dict",
                                    Title = "字典管理"
                                }
                            },
                            new SysMenuDto
                            {
                                Component = "system/dict/data",
                                Name = "DictData",
                                Path = "dict-data",
                                Meta = new Meta
                                {
                                    AlwaysShow = false,
                                    Hidden = true,
                                    KeepAlive = true,
                                    Icon = "dict",
                                    Title = "字典数据"
                                }
                            }
                        }
                    }
                },
                Msg = string.Empty
            };
        }
    }
}
